package Smt.BaseDaoImp;

import Smt.BaseDao.BaseDao;
import Smt.BaseDao.SmtUserDao;
import Smt.Util.SmtUser;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class SmtUserDaoImp implements SmtUserDao {

	BaseDao bd = new BaseDao();
	private ResultSet rs;

	//用户的增删改
	public boolean util(String sql, Object[] u) {
		return bd.util(sql, u);
	}

	//用户的增删改
	public boolean exist(String sql, Object[] u) {
		try {
			return bd.getList(sql, u).next();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	//用户的显示
	public ArrayList<SmtUser> getSmtUserList(Object[] o, String sql) {
		ArrayList<SmtUser> list = new ArrayList<SmtUser>();
		try {
			rs = bd.getList(sql, o);
			while (rs.next()) {
				SmtUser s = new SmtUser(rs.getInt("id"), rs.getString("name"), rs.getString("sex"), rs.getInt("age"), rs.getString("tel"), rs.getString("adds"), rs.getString("rms"), rs.getString("password"));
				list.add(s);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			bd.closeAll();
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

	//单条件数目查询(productName)
	public int SmtUserCount(String n) {
		String sql = "select count(*) from Super_User where name like '%" + n + "%'";
		return bd.Count(sql);
	}
}
